package org.neuedu.ssmp.crm.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.neuedu.ssmp.crm.entity.Serve;
import org.neuedu.ssmp.crm.entity.vo.ResponseEntity;
import org.neuedu.ssmp.crm.service.IServeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/serve")
public class ServeController {
    @Autowired
    private IServeService iServeService;

    @RequestMapping("/findAll")
    public List<Serve> findAll(){
        List<Serve> list = iServeService.list();
        return list;
    }

    @RequestMapping("/add")
    public ResponseEntity add(@RequestBody Serve serve){
        return iServeService.addServe(serve);
    }

    @RequestMapping("/updateById")
    public void edit(@RequestBody Serve serve){
        System.out.println(serve.toString());
        iServeService.updateById(serve);
    }

    @RequestMapping("/delid/{id}")
    public void deleteById(@PathVariable String id){
        iServeService.removeById(Integer.parseInt(id));
    }

    @RequestMapping("/query")
//    public void query(@RequestParam(value = "category") String category,@RequestParam String entry,@RequestParam String valu){
    public List<Serve> query(@RequestBody Serve serve){
        System.out.println("第一次输出"+serve.toString());
        String name = serve.getName();
        System.out.println(name);
        LambdaQueryWrapper<Serve> lambdaQueryWrapper = Wrappers.lambdaQuery();
        LambdaQueryWrapper<Serve> category1 = lambdaQueryWrapper.like(Serve::getName,name);
        return iServeService.list(lambdaQueryWrapper);
    }
}
